package cz.semjobKB.extract.api.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.springframework.stereotype.Component;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.model.TextRun;
import org.apache.poi.hslf.usermodel.SlideShow;

import cz.semjobKB.extract.api.IExtractText;

@Component
public class ExctractFromPpt implements IExtractText {

	
	public String extractText(File file) throws IOException {
		InputStream fis= new FileInputStream(file);
		HSLFSlideShow show=new HSLFSlideShow(fis);
		SlideShow ss=new SlideShow(show);
		Slide[] slides=ss.getSlides();
		StringBuilder builder = new StringBuilder();
		for(int x=0; x<slides.length; x++)
		{
			TextRun[] runs = slides[x].getTextRuns();
			for(int j=0; j<runs.length; j++) {
				TextRun run = runs[j];
				if(run != null) {
					String text = run.getText();
					builder.append(text);					
				}
			}
		}
		return builder.toString();
	}

}
